Jupyterlab3.0安装、配置并选择虚拟环境开机启动

您所在的位置:网站首页 jupyter 启动 参数 Jupyterlab3.0安装、配置并选择虚拟环境开机启动

Jupyterlab3.0安装、配置并选择虚拟环境开机启动

2023-03-10 21:14| 来源: 网络整理| 查看: 265

Jupyter-lab 3.0 安装、配置并选择虚拟环境开机启动1. 安装Jupyter-lab3.02.生成配置文件并设置密码3. 编辑配置文件4. 安装插件4.1 安装中文语言包4.2 debugger 语法检测4.3 代码提示4.4 可交互 matplotlib4.5 自动代码格式化5. 添加到开机启动项TODO 使用Nignx反代理参考链接

1. 安装Jupyter-lab3.0

pip install jupyterlab==3# 或者使用conda安装# conda install -c conda-forge jupyterlab=3

2.生成配置文件并设置密码

jupyter lab --generate-config jupyter lab password

3. 编辑配置文件

vim ~/.jupyter/jupyter_lab_config.py

# 允许跨域访问,在用nginx反向代理jupyter-lab时需要打开c.ServerApp.allow_origin = '*'# 允许远程访问c.ServerApp.allow_remote_access = True# 监听来自所有ip的连接,默认时localhost只能本地访问# 假设主机局域网ip为192.168.1.101,此处设置为局域网ip,则局域网内都可以访问c.ServerApp.ip = '0.0.0.0'# 设置默认打开路径 c.ServerApp.root_dir = "/home/username/code"# 开启jupyter-lab时不自动打开浏览器c.ServerApp.open_browser = False# 默认监听端口c.ServerApp.port = 58000

4. 安装插件

首先enable插件管理

4.1 安装中文语言包

pip install jupyterlab-language-pack-zh-CN

然后在settings→language中切换

4.2 debugger 语法检测

插件Github地址:https://github.com/jupyterlab/debugger

jupyter-lab3.0默认带有debugger,所以不需要额外安装。但缺少依赖包

安装依赖

conda install -c conda-forge xeus-python# 或者# pip install xeus-python

4.3 代码提示

插件Github地址:Language Server Protocol integration for Jupyter

安装方法

# 先安装Language Server Protocol integration for Jupyter-labconda install -c conda-forge jupyterlab-lsp# 或者#pip install jupyterlab-lsp# 再安装语法库pip install 'python-lsp-server[all]'

4.4 可交互 matplotlib

插件Github地址:ipympl

在代码开头插入即可

%matplotlib widget

安装方法:

conda install -c conda-forge ipympl# 或者# pip install ipympl

4.5 自动代码格式化

插件Github地址:Jupyterlab Code Formatter

配置参考链接:https://blog.csdn.net/mighty13/article/details/120024319

安装方法

pip install jupyterlab_code_formatterpip install autopep8

重启jupyter lab

设置→高级编辑器

修改jupyterlab Code Formatter

输入内容:

{"preferences": {"default_formatter": {"python": "autopep8","R": "styler"}}}

通过点击状态栏或者右键即可使用

对全局生效 对当前代码块生效 5. 添加到开机启动项

sudo vim /etc/systemd/system/jupyter-lab.service

输入以下内容

[Unit]Description=jupyter labAfter=network.target # 在网络启动后启动此服务[Service]Type=simpleUser=username # 以此用户启动本程序# 启动脚本ExecStart=/home/marques/.conda/envs/torch-marques/bin/jupyter-lab --no-browser # jupyter-lab路径# 因为我使用anaonda默认虚拟环境启动,所以选择执行脚本方式启动# ExecStart=/home/marques/software/jupyterlabscript/lab.shExecStop=/usr/bin/pkill jupyter-labKillMode=process Restart=always # 程序崩溃后自动重启程序RestartSec=30s # 当程序崩溃后30s重新启动[Install]WantedBy=multi-user.target

切换虚拟环境启动jupyter-lab脚本

#!/bin/bash -l# 上面 -l 参数是指以会话方式打开脚本,否则无法切换anaconda虚拟环境# 下面这段在~/.bashrc复制过来# 其操作是将conda添加到环境变量# 每台服务器安装位置不一定一致,要重新复制# >>> conda initialize >>># !! Contents within this block are managed by 'conda init' !!__conda_setup="$('/home/dell/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"if [ $? -eq 0 ]; theneval "$__conda_setup"elseif [ -f "/home/dell/anaconda3/etc/profile.d/conda.sh" ]; then. "/home/dell/anaconda3/etc/profile.d/conda.sh"elseexport PATH="/home/dell/anaconda3/bin:$PATH"fifiunset __conda_setup# # 切换虚拟环境conda activate torch-marques# 启动jupyter-lab/home/marques/.conda/envs/torch-marques/bin/jupyter-lab --no-browser

设置开机启动

sudo systemctl daemod-relaodsudo systemctl enable jupyter-labsudo systemctl start jupyter-lab

TODO 使用Nignx反代理

挖个坑

参考链接

ubuntu20下anaconda中Jupyterlab3.0配置远程登录

在shell文件中启动anaconda的虚拟环境



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3